<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('测试用例列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="planId" name="planId" th:value="${plan.id}">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>类型：</label>
                                <select name="type" th:with="type=${@dict.getType('test_case')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>模块ID：</label>
                                <input type="text" name="moduleId"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="selectCase()" shiro:hasPermission="system:case:add">
                    <i class="fa fa-plus"></i> 添加用例
                </a>
                <a class="btn btn-danger multiple disabled" onclick="cancelAuthUserAll()" shiro:hasPermission="system:role:remove">
                    <i class="fa fa-remove"></i> 批量移除
                </a>
                <a class="btn btn-warning" onclick="closeItem()">
                    <i class="fa fa-reply-all"></i> 关闭
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:case:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:case:remove')}]];
        var typeDatas = [[${@dict.getType('test_case')}]];
        var prefix = ctx + "system/plan/authCase";

        $(function() {
            var options = {
                url: prefix + "/allocatedList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "测试用例",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'precondition',
                    title: '前置条件'
                },
                {
                    field: 'moduleId',
                    title: '模块ID'
                },
                    {
                        field:'createBy',
                        title:'创建者'
                    },
                    {
                        field: 'createTime',
                        title: '创建时间'
                    },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="cancelAuthCase(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消授权</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 分配用例-取消授权 */
        function cancelAuthCase(caseId) {
            $.modal.confirm("确认要移除该用例吗？", function() {
                $.operate.post(prefix + "/cancel", { "planId": $("#planId").val(), "caseId": caseId });
            })
        }

        /* 分配用例-选择用例 */
        function selectCase() {
            var url = prefix + '/selectCase/' + $("#planId").val();
            $.modal.open("选择用例", url);
        }

    </script>
</body>
</html>